package com.atguigu.gmallrealtime.util;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;

import java.util.concurrent.ExecutionException;

/**
 * @author yhm
 * @create 2023-10-13 9:19
 */
public class RedisUtil {

    public static  StatefulRedisConnection<String, String> getAsyncRedisConnection(){
        RedisClient redisClient = RedisClient.create("redis://hadoop102:6379");
        return redisClient.connect();
    }

    public static void closeAsyncRedisConnection(StatefulRedisConnection<String, String> connection){
        if (connection != null ){
            connection.close();
        }
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        RedisClient redisClient = RedisClient.create("redis://hadoop102:6379");
        StatefulRedisConnection<String, String> connect = redisClient.connect();
        RedisAsyncCommands<String, String> async = connect.async();
        RedisFuture<String> stringRedisFuture = async.get("dim_sku_info:15");
        String value = stringRedisFuture.get();
        System.out.println(value);
    }
}
